package org.jgs1904.apachepoidemo.game;

import java.util.*;
import java.util.stream.Collectors;

class Champion {
    String name;
    String[] bonds;
    int stars;

    public Champion(String name, String[] bonds, int stars) {
        this.name = name;
        this.bonds = bonds;
        this.stars = stars;
    }

    public String getName() {
        return name;
    }

    public String[] getBonds() {
        return bonds;
    }

    public int getStars() {
        return stars;
    }
}

public class Main {
    public static void main(String[] args) {
        Champion[] champions = {
                new Champion("安妮", new String[]{"EMO", "法师"}, 1),
                new Champion("伊芙丽", new String[]{"KDA", "刺客"}, 1),
                new Champion("压缩", new String[]{"法师", "KDA", "射手"}, 3)
        };

        Map<String, List<String>> bondMap = Arrays.stream(champions)
                .flatMap(champion -> Arrays.stream(champion.getBonds())
                        .map(bond -> new AbstractMap.SimpleEntry<>(bond, champion.getName() + " " + champion.getStars())))
                .collect(Collectors.groupingBy(Map.Entry::getKey, Collectors.mapping(Map.Entry::getValue, Collectors.toList())));

        for (Map.Entry<String, List<String>> entry : bondMap.entrySet()) {
            StringBuilder result = new StringBuilder(entry.getKey() + "：");
            for (String championInfo : entry.getValue()) {
                result.append(championInfo).append("， ");
            }
            System.out.println(result.substring(0, result.length() - 2));
        }
    }

    public static List<Champion> sortChampionsByStars(Champion[] champions) {
        return Arrays.stream(champions)
                .sorted(Comparator.comparingInt(Champion::getStars))
                .collect(Collectors.toList());
    }

}
